package com.yabushan.web.utils.excelUtils;

import org.apache.poi.ss.usermodel.Workbook;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.net.URLEncoder;

/**
 * @Author yabushan
 * @Date 2021/1/15 15:11
 * @Version 1.0
 */
public class ExcelDownLoad {





    /**
     * 导出excel
     * @param fileName
     * @param response
     * @param workbook
     */
    public static void downLoadExcel(String fileName, HttpServletResponse response, Workbook workbook)
    {
        try
        {

            String filename=fileName;
            filename = URLEncoder.encode(filename, "UTF-8");
            response.setHeader("Content-Disposition", "attachment;filename="+filename+".xlsx");
            response.addHeader("Pargam", "no-cache");
            response.addHeader("Cache-Control", "no-cache");
//            application/octet-stream
            response.setContentType("application/force-download");
           /* response.setCharacterEncoding("UTF-8");
            response.setHeader("content-Type", "application/vnd.ms-excel");
            response.setHeader("Content-Disposition",
                    "attachment;filename=\"" + URLEncoder.encode(fileName, "UTF-8") + "\"");*/
            workbook.write(response.getOutputStream());
        }
        catch (IOException e)
        {
            e.printStackTrace();
        }
    }
}
